/*
 * Copyright 2013-2019 Xia Jun(3979434@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************************
 *                                                                                     *
 *                        Website : http://www.farsunset.com                           *
 *                                                                                     *
 ***************************************************************************************
 */
package com.huilian.netty.handler;


import com.alibaba.fastjson.JSON;
import com.huilian.netty.model.CIMSession;
import com.huilian.netty.model.SocketMessage;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 心跳handler，主要是让netty重置cheannel的空闲时间
 */
@Component
public class HeartbeatHandler implements CIMRequestHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger(HeartbeatHandler.class);

    @Override
    public void process(CIMSession session, SocketMessage body) {

        String json = JSON.toJSONString(body);
        LOGGER.info("接收到客户端心跳：{}", json);
        body.setId(session.getNid());
        TextWebSocketFrame textWebSocketFrame1 = new TextWebSocketFrame(JSON.toJSONString(body));
        session.getSession().writeAndFlush(textWebSocketFrame1);
    }
}
